package service

import (
	"context"
	__ "user_srv/basic/userproto"
	"user_srv/handler/dao"
)

// 添加地址
func (s *Server) AddAddress(_ context.Context, in *__.AddAddressReq) (*__.AddAddressResp, error) {
	id, err := dao.AddAddress(in.UserId, in.Address)
	if err != nil {
		return nil, err
	}
	return &__.AddAddressResp{Id: id}, nil
}

// 地址修改
func (s *Server) UpdateAddress(_ context.Context, in *__.UpdateAddressReq) (*__.UpdateAddressResp, error) {
	err := dao.UpdateAddress(in.Id, in.Address)
	if err != nil {
		return nil, err
	}
	return &__.UpdateAddressResp{
		Res: true,
	}, nil
}

// 删除地址
func (s *Server) DeleteAddress(_ context.Context, in *__.DeleteAddressReq) (*__.DeleteAddressResp, error) {
	err := dao.DeleteAddress(in.Id)
	if err != nil {
		return nil, err
	}
	return &__.DeleteAddressResp{
		Res: true,
	}, nil
}
